package com.dgut.legalservice.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class LoginHandleInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException, IOException {
       Object user = request.getSession().getAttribute("user");
       if (user==null||user.equals("")){
            request.setAttribute("msg","没有权限请先登录");
            request.getRequestDispatcher("/login/login").forward(request,response);
            return false;
       }
       else{ //已登录，放行
           return true;
       }
    }


}
